package com.xiashitech.apiservice.config;


//import com.xiashitech.apiservice.job.listener.RabbitMqHandleService;
import com.xiashitech.apiservice.dto.AgentIdentityDTO;
import com.xiashitech.apiservice.grpc.IncrementalCacheService;
import com.xiashitech.apiservice.job.listener.RbMQReceiverHandler;
import lombok.RequiredArgsConstructor;

import org.springframework.amqp.core.*;
import org.springframework.amqp.rabbit.connection.ConnectionFactory;

import org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;

import org.springframework.context.annotation.*;
import org.springframework.stereotype.Component;

@Configuration
@Component
@Import(cn.hutool.extra.spring.SpringUtil.class)
@RequiredArgsConstructor(onConstructor = @_(@Autowired))
public class RabbitMqConfig {
    public static String EXCHANGE_NAME = "topicExchange";
    public static String DAM_QUEUE = "damQueue";
    public static String DESENSITIZATION_QUEUE = "desensitizationQueue";
    public static String DAM_ROUTING_KEY ="topic.dam";
    public static String DESENSITIZATION_ROUTING_KEY ="topic.desensitizationChange";


    //创建两个队列
    @Bean(name = "damQueue")
    public Queue damQueue() {
        return new Queue(DAM_QUEUE);
    }


    @Bean(name = "desensitizationQueue")
    public Queue desensitizationQueue() {
        return new Queue(DESENSITIZATION_QUEUE );
    }

    //创建交换机
    @Bean
    public TopicExchange exchange() {
        return new TopicExchange(EXCHANGE_NAME);
    }
 /*   public SimpleMessageListenerContainer messageContainer(ConnectionFactory connectionFactory) {
        SimpleMessageListenerContainer container = new SimpleMessageListenerContainer(connectionFactory);
        return container;
    }
*/
   @Bean
    Binding binding1(@Qualifier("damQueue") Queue queueDam, TopicExchange exchange) {
        return BindingBuilder.bind(queueDam).to(exchange).with(DAM_ROUTING_KEY);
    }

   @Bean
    Binding binding2(@Qualifier("desensitizationQueue") Queue queuemessages, TopicExchange exchange) {
        return BindingBuilder.bind(queuemessages).to(exchange).with(DESENSITIZATION_ROUTING_KEY);
    }

}

